﻿#region License statement
// NJamb, a specification and delta-specification DSL
// Copyright (c) 2010-2011, Mark Knell
// Published under the MIT License; all other rights reserved
#endregion

#region using...
using System;
using System.Linq.Expressions;
using NJamb.Parser.SpecificationBuilders.SubjectHas.Delta.Singular;
using NJamb.Parser.SpecificationBuilders.SubjectIs.Delta.Singular;
using NJamb.Specifications.Delta;
using NJamb.Specifications.Simple;
using Stile.Patterns.SelfDescribingPredicates;
using Stile.Patterns.SelfDescribingPredicates.Evaluators;
#endregion

namespace NJamb.Parser.SpecificationBuilders.Delta.Singular
{
    public class SingularDeltaSpecificationBuilder<TSubject> : DeltaSpecificationBuilder<TSubject>,
        ISingularDeltaSpecificationBuilder<TSubject>,
        ICollaboratingSpecificationBuilder<TSubject, IDeltaSpecification>
    {
        public SingularDeltaSpecificationBuilder(ICollaboratingSimpleSpecification<TSubject> before)
            : base(before) {}

        public ISingularDeltaHas<TSubject> Has
        {
            get { return new SingularDeltaHas<TSubject>(this); }
        }

        public INegatableSingularDeltaIs<TSubject> Is
        {
            get { return new NegatableSingularDeltaIs<TSubject>(this, Negated.False); }
        }
        public ICollaboratingSpecificationBuilder<TSubject, IDeltaSpecification> Xray
        {
            get { return this; }
        }

        public IDeltaSpecification Satisfies(ISelfDescribingPredicate<TSubject> selfDescribingPredicate)
        {
            return Specify(selfDescribingPredicate);
        }

        public IDeltaSpecification Satisfies(Expression<Func<TSubject, bool>> lambdaPredicate)
        {
            Evaluator<TSubject, TSubject> evaluator = Expect<TSubject>.Satisfies(lambdaPredicate);
            return Satisfies(evaluator);
        }
    }
}
